import geoip2.database

# 打开 GeoLite2 数据库
reader = geoip2.database.Reader('GeoLite2-City.mmdb')

# 查询 IP 归属地
ip_address = '128.101.101.101'
response = reader.city(ip_address)

country = response.country.name
region = response.subdivisions.most_specific.name  # 省份信息
city = response.city.name
latitude = response.location.latitude
longitude = response.location.longitude

print(f"IP 地址: {ip_address}")
print(f"国家: {country}")
print(f"省份: {region}")
print(f"城市: {city}")
print(f"经度: {latitude}, 纬度: {longitude}")

reader.close()
